#include "TwOgreButtonVariable.h"

#include "TwOgreWindow.h"

namespace TwOgre{
	ButtonVariable::ButtonVariable(ButtonParams& params)
        : Variable(params.parent_, params.name_, params.type_)
    {
        TwAddButton(params.parent_->getTweakBar(), params.name_.c_str(), params.buttonCB_, params.data_, "");
		if(params.label_.compare("") != 0)
		{
			setLabel(params.label_);
		}
		if(params.group_.compare("") != 0)
		{
			setGroup(params.group_);
		}
		if(params.help_.compare("") != 0)
		{
			setHelp(params.help_);
		}
		if(params.shortcut_.compare("") != 0)
		{
			setShortcut(params.shortcut_);
		}
    }
	
    ButtonVariable::ButtonVariable(Window* parent, const Ogre::String& name, const Ogre::String& label, const Ogre::String& groupName, const Ogre::String& help, TwButtonCallback  callback, void* data)
        : Variable(parent, name, TW_TYPE_UNDEF)
    {
        TwAddButton(parent->getTweakBar(), name.c_str(), callback, data, "");
		if(label.compare("") != 0)
		{
			setLabel(label);
		}
		if(groupName.compare("") != 0)
		{
			setGroup(groupName);
		}
		if(help.compare("") != 0)
		{
			setHelp(help);
		}
    }
	
    ButtonVariable::~ButtonVariable()
    {
        TwRemoveVar(mParent->getTweakBar(), mName.c_str());
    }
	
    void ButtonVariable::setShortcut(const Ogre::String& execute)
	{
		std::stringstream ss;
		ss << " '" << mParent->getName() << "'/'" <<  mName 
		   << "' Key='" << execute << "' ";

		TwDefine(ss.str().c_str());
	}
}; // End Namespace